package com.hexacta.hrs.test.data;

import java.util.List;
import java.util.Map;

import org.vectrics.company.CompanyPersonGroupType;
import org.vectrics.user.UserPrivilegeType;

/**
 * Test data dependency creator for the CompanyPersonGroupType class.
 * 
 * @author tpollak
 */
public class CompanyPersonGroupTypeTestDataDependencyCreator extends AbstractTestDataDependencyCreator {

    public CompanyPersonGroupTypeTestDataDependencyCreator(List<TestDataDependencyCreator> dependencies) {
        super(dependencies);
    }

    public void createDependentTestData(Map<String, Object> context) {
        // Create the Company Person Group Types
        this.createAndInsertCompanyPersonGroupType("admin", "phrase.administrator", "assign.admin.cmpy.grp");
        this.createAndInsertCompanyPersonGroupType("finance.admin", "person.priv.group.finance.admin", "finance.admin");
        this.createAndInsertCompanyPersonGroupType("hiring.mgr", "phrase.hiring.manager", "assign.hire.mgr.cmpy.grp");
        this.createAndInsertCompanyPersonGroupType("primary.contact", "phrase.primary.contact",
                "assign.contact.cmpy.grp");
        this.createAndInsertCompanyPersonGroupType("recruiter", "phrase.recruiter", "assign.recruit.cmpy.grp");
        this.createAndInsertCompanyPersonGroupType("recruiter.mgr", "phrase.recruiter.manager",
                "assign.recr.mgr.cmpy.grp");
    }

    private void createAndInsertCompanyPersonGroupType(String code, String description, String privilegeCode) {
        CompanyPersonGroupType groupType = this.createCompanyPersonGroupType(code, description, privilegeCode);
        this.insertCodedObject(groupType);
    }

    private CompanyPersonGroupType createCompanyPersonGroupType(String code, String description, String privilegeCode) {
        CompanyPersonGroupType groupType = new CompanyPersonGroupType();
        groupType.setCode(code);
        groupType.setDescriptionCode(description);
        UserPrivilegeType privilege = (UserPrivilegeType) this.getCurrentSession().load(UserPrivilegeType.class,
                privilegeCode);
        groupType.setPrivilegeWhoCanAssign(privilege);
        return groupType;
    }
}
